<template>
  <ych-modal
    :fullscreen="false"
    size="middle"
    :title="$t('m.system.portal.entity.theme')"
    :visible="visible"
    @cancel="handleCancel"
  >
    <a-divider orientation="left" v-if="!hideLayout">{{$t('m.system.portal.entity.layoutset')}}</a-divider>
    <a-tooltip style="display: inline-flex; width: 80px; height: 60px; margin: 0 24px;" v-if="!hideLayout">
      <template slot="title">
        {{$t('m.system.portal.entity.leftNavigation')}}
      </template>
      <div style="position:relative; cursor: pointer; width: 100%; height: 100%;" @click="handleLayout('sidemenu');handleMenuTheme('light');">
        <img src="https://gw.alipayobjects.com/zos/rmsportal/JopDzEhOqwOjeNTXkoje.svg" style="width: 100%; height: 100%;">
        <div style="position: absolute; top: 10px; left: 20px; color: #1890ff;" v-if="layoutMode === 'sidemenu'">
          <ych-icon type="check" style="font-size: 40px"/>
        </div>
      </div>
    </a-tooltip>

    <a-tooltip style="display: inline-flex; width: 80px; height: 60px; margin: 0 24px;" v-if="!hideLayout">
      <template slot="title">
        {{$t('m.system.portal.entity.topNavigation')}}
      </template>
      <div style="position:relative; cursor: pointer; width: 100%; height: 100%;" @click="handleLayout('topmenu');handleMenuTheme('dark');">
        <img src="https://gw.alipayobjects.com/zos/rmsportal/KDNDBbriJhLwuqMoxcAr.svg" style="width: 100%; height: 100%;">
        <div style="position: absolute; top: 10px; left: 20px; color: #1890ff;" v-if="layoutMode === 'topmenu'">
          <ych-icon type="check" style="font-size: 40px"/>
        </div>
      </div>
    </a-tooltip>

    <a-tooltip style="display: inline-flex; width: 80px; height: 60px; margin: 0 24px;" v-if="!hideLayout">
      <template slot="title">
        {{$t('m.system.portal.entity.leftAndTopNavigation')}}
      </template>
      <div style="position:relative; cursor: pointer; width: 100%; height: 100%;" @click="handleLayout('topsidemenu');handleMenuTheme('dark');">
        <img src="https://gw.alipayobjects.com/zos/antfincdn/x8Ob%26B8cy8/LCkqqYNmvBEbokSDscrm.svg" style="width: 100%; height: 100%;">
        <div style="position: absolute; top: 10px; left: 20px; color: #1890ff;" v-if="layoutMode === 'topsidemenu'">
          <ych-icon type="check" style="font-size: 40px"/>
        </div>
      </div>
    </a-tooltip>

    <a-divider orientation="left">{{$t('m.system.portal.entity.skinset')}}</a-divider>
    <a-tooltip v-for="(item, index) in colorList" :key="index"
               style="height: 50px; width: 80px; margin: 0 10px 10px 10px; cursor:pointer">
      <template slot="title">
        {{ item.key }}
      </template>
      <a-tag :color="item.color" @click="changeColor(item.color)" style="text-align: center; vertical-align: middle;">
        <ych-icon type="check" v-if="item.color === primaryColor" style="font-size: 40px"></ych-icon>
      </a-tag>
    </a-tooltip>

    <template slot="footer">
      <a-button key="back" @click="handleCancel">{{ $t('m.common.button.close') }}</a-button>
    </template>
  </ych-modal>
</template>

<script>

  import { updateTheme, colorList } from '@/framework/tools/setting'
  import { mixin, mixinDevice } from '@/utils/mixin.js'
  import { triggerWindowResizeEvent } from '@/utils/util'

  export default {
    mixins: [mixin, mixinDevice],
    props: {
      hideLayout: Boolean
    },
    data() {
      return {
        visible: false,
        colorList,
      }
    },
    methods: {
      handleCancel(){
        this.visible = false
      },
      showDrawer() {
        this.visible = true
      },
      handleMenuTheme (theme) {
        this.$store.dispatch('ToggleTheme', theme)
      },
      handleLayout (mode) {
        this.$store.dispatch('ToggleLayoutMode', mode)
        // 因为顶部菜单不能固定左侧菜单栏，所以强制关闭
        this.handleFixSiderbar(false)
        // 触发窗口resize事件
        triggerWindowResizeEvent()
      },
      changeColor (color) {
        if (this.primaryColor !== color) {
          this.$store.dispatch('ToggleColor', color)
          updateTheme(color)
        }
      },
      handleFixSiderbar (fixed) {
        if (this.layoutMode === 'topmenu') {
          fixed = false
        }
        this.$store.dispatch('ToggleFixSiderbar', fixed)
      }
    },
  }
</script>
